package com.t2t.top.action.$15observer.spring;

import java.util.Collection;
import java.util.LinkedList;

/**
 * Created by yangpengfei on 2016/8/4.
 */
public class SimpleApplicationEventMulticaster {

    public void multicastEvent(ApplicationEvent event) {
        //遍历集合
        for (ApplicationListener listener : getApplicationListeners()) {
            listener.onApplicationEvent(event);
        }
    }

    private Collection<ApplicationListener> getApplicationListeners() {
        Collection<ApplicationListener> listeners = retrieveApplicationListeners();
        return listeners;
    }

    private Collection<ApplicationListener> retrieveApplicationListeners() {
        LinkedList<ApplicationListener> allListeners = new LinkedList<ApplicationListener>();
        ApplicationListener listener = new MyListener1();
        allListeners.add(listener);
        listener = new MyListener2();
        allListeners.add(listener);
        return allListeners;
    }


}
